import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:flutter_base/config/app_color.dart';

class CommonTabBar extends StatelessWidget {
  final TabController tabController;
  final List<Widget> tabs;
  final bool isScrollable;
  final Color? unselectedLabelColor;
  final Color? labelColor;
  final Function(int)? onTap;
  final EdgeInsetsGeometry? labelPadding;
  final EdgeInsetsGeometry? tabContentPadding;
  final TextStyle? unselectedLabelStyle;
  final TextStyle? labelStyle;
  final Decoration? indicator;
  final EdgeInsetsGeometry? indicatorPadding;
  final TabBarIndicatorSize? indicatorSize;

  const CommonTabBar({
    super.key,
    required this.tabController,
    required this.tabs,
    this.onTap,
    this.labelColor,
    this.isScrollable = true,
    this.unselectedLabelColor,
    this.labelPadding,
    this.tabContentPadding,
    this.unselectedLabelStyle,
    this.labelStyle,
    this.indicator,
    this.indicatorPadding,
    this.indicatorSize,
  });

  @override
  Widget build(BuildContext context) {
    return TabBar(
      controller: tabController,
      padding: tabContentPadding ?? EdgeInsets.symmetric(horizontal: 16.w),
      onTap: onTap,
      tabAlignment: isScrollable ? TabAlignment.start : null,
      labelPadding:
          labelPadding ?? EdgeInsets.symmetric(horizontal: 16.w, vertical: 8.w),
      labelColor: labelColor ?? AppColor.color282828,
      unselectedLabelColor: unselectedLabelColor ?? AppColor.colorBDBDBD,
      unselectedLabelStyle: unselectedLabelStyle ??
          TextStyle(fontSize: 16.sp, fontWeight: FontWeight.w400),
      labelStyle:
          labelStyle ?? TextStyle(fontSize: 16.sp, fontWeight: FontWeight.bold),
      dividerColor: Colors.transparent,
      isScrollable: isScrollable,
      indicator: indicator ??
          UnderlineTabIndicator(
            borderSide: const BorderSide(
              width: 2,
              color: AppColor.primary,
            ),
            insets: EdgeInsets.symmetric(horizontal: 12.w),
          ),
      indicatorPadding: indicatorPadding ?? EdgeInsets.only(top: 8.w),
      indicatorSize: indicatorSize ?? TabBarIndicatorSize.label,
      indicatorWeight: 0.0,
      splashFactory: NoSplash.splashFactory,
      overlayColor:
          WidgetStateProperty.resolveWith<Color?>((Set<WidgetState> states) {
        return Colors.transparent;
      }),
      tabs: tabs,
    );
  }
}
